/**
 * ajax封装get/post
 * @author xxt
 * @param {String} url 
 * @param {String} params 
 * @param {Function} callback 
 * @param {Function} headersFn 
 * @param return undefined
 */
function get(url,params,callback,headersFn){
    const xhr = new XMLHttpRequest
    xhr.onreadystatechange = function(){
        if(xhr.readyState ==4){
            if(xhr.status ==200 ){
                let res = JSON.parse(xhr.responseText)
                callback(res)
            }else{
                alert(xhr.status)
            }
        }
    }
    xhr.open('get',`${url}?${params}`)
    if(headersFn) headersFn(xhr)
    xhr.send(null)
} 

function post(url,params,callback,headersFn){
    const xhr = new XMLHttpRequest
    xhr.onreadystatechange = function(){
        if(xhr.readyState ==4){
            if(xhr.status ==200 ){
                let res = JSON.parse(xhr.responseText)
                callback(res)
            }else{
                alert(xhr.status)
            }
        }
    }
    xhr.open('post',url)
    xhr.setRequestHeader('content-type','application/x-www-form-urlencoded')
    if(headersFn) headersFn(xhr)
    xhr.send(params)
} 